// 重写数组的方法

let oldArrayMethods = Array.prototype;

export let arrayMethods = Object.create(oldArrayMethods);





const methods = [
  'push',
  'shift',
  'unshift',
  'pop',
  'sort',
  'splice',
  'reverse'
]

methods.forEach(method => {
  arrayMethods[method] = function(...args) {
    console.log('用户diayongl')
    const result = oldArrayMethods[method].apply(this, args)
    // 数组新加的元素也要注意转为响应式的
    let inserted;
    let ob = this.__ob__;
    switch (method) {
      case 'push':
      case 'unshift':
        inserted = args
        break;
      case 'splice':
        inserted = args.slice(2)
      default:
        break;
    }
    if(inserted) ob.observeArray(args);

    ob.dep.notify()
    return result
  }
})